function lodingtable(){
	var stuInfo = $('#selectForm').serializeObject();
	var selectJsonStr = JSON.stringify(stuInfo);//将表单中的数据转成json
	$('#stuTable').DataTable({
		"processing": true, //处理状态
        "serverSide": true, //开启服务器模式     默认不开启的
        "stateSave":false, //开启浏览器本地缓存,不开启
        "autoWidth":false,  //自动适应宽高
        "ordering": true,// 开启排序
        "paging": true, //开启自动分页
        "iDisplayLength":10, //每页展示的条数   默认展示10条
        "bLengthChange":true, //可以改变分页数
        "info": true,					//显示表格信息
        "bDestroy": true, //如已存在相同dataTable对象，则销毁重建
        "searching": false,	//关闭搜索
        "aLengthMenu":[[10,20,30],[10,20,30]],
	    "sDom":'<"info-toolbar">rtilp',
	    "columns" : [   
	         { "data" : "name"},
	         { "data" : "niming","sDefaultContent" : "匿名者"},
	         { "data" : "age"},
	         { "data" : "sex","class" : ""},
	         { "data" : "class_name","sDefaultContent" : ""},
	         { "data" : "create_time","sDefaultContent" : ""}
	         //{ "data" : "classname","sDefaultContent" : ""},
	         //{ "data" : "createtime","sDefaultContent" : ""}
	     ],
	     "createdRow": function (row, data, index ) {
	    	 console.log("第"+index+"行的信息");
	    	 console.log(data);
	    	 $(row).children('td').attr('style', 'text-align: center;');
	        	if(index % 2 == 1){
	        		$(row).css("background","#F4F4F4");
	        	}
	        },
	     "columnDefs": [
			   {
			     "targets": [3],
			     "data":"sex",
			     "render": function(data, type, full) {
			    	 var sexNa="男";
			    	 if(data==0){
			    	     sexNa="女";
			    	 }
			    	 return sexNa;
			       }
			     },        				
			     {
			      "targets": [6],
			      "data":"id",
			      "render": function(data, type, full) {
			           return "<a href='#' onclick='updateStu(\""+data+"\")'> 编辑</a>| "+ "<a href='#' onclick='deleteStu(\""+data+"\")'> 删除</a> ";
			       }
			    }
             ],
             "ajax": {
            	 "type":"post",
                 "url": getRootPath()+"/student/queryStuList.action",
                 "dataType":"json",
                 "data":{signupForm:selectJsonStr}
             },
             "language": {   //定义统一的提示语言
            	 "decimal":",",
            	 "thousands":".",
            	 "lengthMenu": "每页显示 _MENU_ 条记录",
                 "zeroRecords": "暂无数据",
                 "info": " _PAGE_ / _PAGES_",
                 "infoEmpty": "没有数据",
                 "infoFiltered": "(filtered from _MAX_ total records)",
                 "emptyTable":     "没有数据",
                 "info":           "当前显示第 _START_ 到第 _END_ 条,共 _TOTAL_ 条记录",
                 "infoEmpty":      "显示第 0 到第 0 条（总 0 条）",
                 "infoFiltered":   "(来自 _MAX_ 条的过滤数据)",
                 "infoPostFix":    "",
                 "thousands":      ",",
                 "loadingRecords": "载入中...",
                 "processing":     "正在处理中...",
                 "search":         "搜索：",
                 "zeroRecords":    "无相关数据",
                 "paginate": {
                     "first":      "首页",
                     "last":       "尾页",
                     "next":       "下一页",
                     "previous":   "上一页"
                 }, 
                 "aria": {
                     "sortAscending":  ": 升序排列",
                     "sortDescending": ": 降序排列"
                 }
             
             }
	    });
	 
}
$(function(){
	jQuery_dataTable_extend_FirstAndEnd();

	lodingtable();}
);

layui.use(['form','element','layer'], function(){
	  
	  $("#addStu").click(function(){
		  parent.layer.open({
			  title:"添加学生",
			  type: 2,
			  id:100,
			  area: ['400px', '480px'],
			  content: getRootPath()+'/students/info/addStu.jsp' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		  });
	});
})	
function updateStu(id){
	layui.use('layer', function(){
		  var layer = layui.layer;
		  parent.layer.open({
			  title:"修改员工信息",
			  type: 2,
			  area: ['400px', '500px'],
			  content: getRootPath()+'/students/info/addStu.jsp?id='+id ,
			  data:{"id":id}
		  });
	});
}
/**
 * 删除访谈信息
 */
function deleteStu(id){

	parent.layer.confirm('确定要删除这条信息吗？', {
		  btn: ['是', '否'] //可以无限个按钮
		}, function(index, layero){
		  //按钮【按钮一】的回调
			$.ajax({
		        url : getRootPath()+"/student/deleteStu.action",
		        type : "post",
		        data : {
		            id : id
		        },
		        datatype : "text",
		        success : function (data) {
		        	parent.layer.msg('删除成功', {
						  icon: 1,
						  time: 500 //（如果不配置，默认是3秒）
					}, function(){
							var data_pjax=$("#admui-siteConTabs ul>li.active>span",window.parent.document).attr("data-pjax");
							parent.document.getElementById(data_pjax).contentWindow.lodingtable();
							parent.layer.closeAll();
							
					});
		        }
		    })
		}, function(index){
		  //按钮【按钮二】的回调
			layer.closeAll('dialog');
		});
}

function queryStudent(){
	 lodingtable();
}